export default {
    namespace: 'user',
    state: { username: '' },
    reducers: {
        login(state, action) { return { ...state, username: action.data.username} },
    },
    effects: {
        *getUset(action, { call, put }) {
            const res = yield call(
                ()=>{
                    return fetch('/api/login', {
                        body: JSON.stringify(action.data), // must match 'Content-Type' header
                        cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
                        credentials: 'same-origin', // include, same-origin, *omit
                        headers: {
                            'user-agent': 'Mozilla/4.0 MDN Example',
                            'content-type': 'application/json'
                        },
                        method: 'POST', // *GET, POST, PUT, DELETE, etc.
                        mode: 'cors', // no-cors, cors, *same-origin
                        redirect: 'follow', // manual, *follow, error
                        referrer: 'no-referrer', // *client, no-referrer
                    }).then(res=>{return res.json()})
                }
            )
            yield put({ type: 'login',data:res });
        },
    },
}